///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////
// PictureCtrl.h
// 
// Author: Tobias Eiseler
//
// E-Mail: tobias.eiseler@sisternicky.com
// 
// Function: A MFC Picture Control to display
//           an image on a Dialog, etc.
///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////

#pragma once
#include "afxwin.h"

#include <vector>

#include <GdiPlus.h>
#include <Gdipluseffects.h>
#include <Gdiplusheaders.h>

#include "ArchiveProcGUIDoc.h"
#include "Observer.h"
#include "ImageDataset.h"

#include "ImageObject.h"
#include "ImageProps.h"

#include "ImageObjectTypeTool.h"
#include "PtShapeTool.h"
#include "SelectTool.h"


class CPictureCtrl : public CStatic
{
public:

	//Constructor
	CPictureCtrl(void);

	//Destructor
	~CPictureCtrl(void);

public:

	//Loads an image from a file
	BOOL LoadFromFile(CString &szFilePath);

	//Loads an image from an IStream interface
	BOOL LoadFromStream(IStream* piStream);

	//Loads an image from a byte stream;
	BOOL LoadFromStream(BYTE* pData, size_t nSize);

	//Loads an image from a Resource
// 	BOOL LoadFromResource(HMODULE hModule, LPCTSTR lpName, LPCTSTR lpType);

	//Overload - Single load function
	BOOL Load(CString &szFilePath);
	BOOL Load(IStream* piStream);
	BOOL Load(BYTE* pData, size_t nSize);
// 	BOOL Load(HMODULE hModule, LPCTSTR lpName, LPCTSTR lpType);

	//Frees the image data
	void FreeData();

protected:
	virtual void PreSubclassWindow();

	//Draws the Control
	virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	virtual BOOL OnEraseBkgnd(CDC* pDC);
//	DECLARE_MESSAGE_MAP()

private:

	//Internal image stream buffer
	IStream* m_pStream;

	//Control flag if a pic is loaded
	BOOL m_bIsPicLoaded;

public:
	DECLARE_MESSAGE_MAP()
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);

public:
	ImageObject *GetSelImageObject() { return GetSelImageProperties()->GetSelImageObject(); }
	ImageProps  *GetSelImageProperties() { return CArchiveProcGUIDoc::GetActiveDoc()->GetSelImageProperties(); }
	ImageObjectTypeTool *GetActiveTool() { return CArchiveProcGUIDoc::GetActiveDoc()->GetSelImageObjectTypeTool(); }
	bool		IsShowImageObjects() { return CArchiveProcGUIDoc::GetActiveDoc()->IsShowImageObjects(); }
	ImageObjectTypeTool *GetToolForImageObject(ImageObject *pImageObject) { return  CArchiveProcGUIDoc::GetActiveDoc()->GetToolForImageObject(pImageObject);  }
private:
	void DrawImageObjects(void *pGraphics, ImageProps *pSelImageProps);
	void RefreshImageObjectArea(ImageObject *pSelImageObject, int UpdateAllViewslHint);
};
